/**
* @author maze | guavestudios.com
* @license MIT License see LICENSE.TXT
* @version 0.1
*/
package com.guavestudios.fcon.format {
	import flash.text.TextField;
	import flash.text.TextFormat;

	public class DefaultAppender implements IAppender,IScrollableAppender{
		
		//{ STATIC
	
		//}
		
		//{ MEMBERS
		private var output:TextField;
		private var linenumber:int=0;
		private var numberFormat:TextFormat = new TextFormat("arial", 10, 0xAAAAAA);
		private var doTrace:Boolean=false;
		//}
		
		//{ GETTER-SETTER
		/**
		* TODO Insert description from GET output here.
		*  
		*  @return TextField
		*/
		public function getOutput():TextField {
			return this.output;
		}
		/**
		* TODO Insert description from SET output here.
		*  
		*  @param poutput[TextField]
		*  @return
		*/
		public function setOutput(poutput:TextField):void {
			this.output = poutput;
		}
		public function setTrace(b:Boolean):void
		{
			doTrace = b;
		}
		//}
		public function DefaultAppender() {
			
			
			init();	
		}
		private function init():void {
			
		}
		//{ PUBLIC FUNCTIONS
		public function append(s:String):void
		{
			if (doTrace) 
				trace(s);
			
			var ns:String=leedingZeros(linenumber++,4)+":";
			var si:int=output.length;
			output.appendText(ns+"\t"+s+"\n");
			output.setTextFormat(numberFormat, si, si + ns.length);
			
			output.scrollV=output.maxScrollV;
			//stage.loaderInfo.parameters
			//FlashConnect.trace(s);
		}
		public function clear():void
		{
			output.text="";
		}
		public function scrollBottom():void
		{
			output.scrollV = output.maxScrollV;
		}
		public function scrollTop():void
		{
			output.scrollV=0;
		}
		public function scrollToLine(l:int):void
		{
			return;
		}
		public function scrollUp():void
		{
			output.scrollV=Math.max(output.scrollV-3,0);
		}
		public function scrollDown():void
		{
			output.scrollV=Math.min(output.maxScrollV,output.scrollV+3);
		}
		//}
		
		//{ OVERRIDEN METHODS
		
		//}
		
		//{ PRIVATE FUNCTIONS
		private function leedingZeros(val:int,num:int):String
		{
			var res:String=String(val);
			while (res.length<num)
				res="0"+res;//res+="0("+val+"<"+Math.pow(10,num)+")";
			return res;
		}
		//}

	}
	
}
